#!/usr/bin/python
# -*- coding:utf-8 -*-
#基数排序
#@author: wklken@yeah.net

#lsd方式，从最右边开始
def radix_sort(l):
    radix = 10
    base = 1
    cell = [ [] for i in range(10)]
    first_cell_size = 0
    
    while first_cell_size != len(l):
        for j in l:
            cell[(j%radix)/base].append(j)
        radix *= 10
        base *= 10
        first_cell_size = len(cell[0])
        l = reduce(lambda x,y: x + y, cell)
        cell = [ [] for i in range(10)]
        
    print l

l = [8, 14, 3, 7, 5, 29, 26, 1]
radix_sort(l)  